Skip to content

Feature/system collectors - #2117

Open
harryzhang-wq wants to merge 4 commits into
masterfrom
feature/system-collectors
Open

harryzhang-wq wants to merge 4 commits into
masterfrom
feature/system-collectors

Conversation

@harryzhang-wq

Copy link
Copy Markdown
Contributor

Summary

Extends the Inventory Collector framework (#2115) with system collectors that
report the container's actual resource allocation, so startup events carry real
per-container resource inventory instead of an empty body.

Motivation

The existing resourceCollector reports host-level values (runtime.NumCPU()
and /proc/meminfo). Inside a container these over-report — they reflect the
node, not the cgroup limit the customer was allocated. To measure real usage
(and detect contract breaches) we need the cgroup-enforced limits.

Changes

Two new collectors, each implementing ECollector[Metric] and self-registering
via init() — additive, the existing resourceCollector is untouched:

Collector Metrics Source
collector_cgroup.go system_cpu_limit, system_memory_limit cgroup v1 (cpu.cfs_quota_us/cpu.cfs_period_us, memory.limit_in_bytes) and v2 (cpu.max, memory.max); v2 detected via cgroup.controllers
collector_filesystem.go system_fs_total, system_fs_free unix.Statfs under a configurable path (default /)

Unlimited limits or absent cgroup files are treated as "nothing to push" (not an
error), so the collector is safe outside a container.

@cla-bot cla-bot Bot added the cla-signed label Jul 3, 2026
@harryzhang-wq
harryzhang-wq force-pushed the feature/system-collectors branch from fbb0d11 to 28da754 Compare July 3, 2026 12:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Extends the Inventory Collector framework by adding a postStart “collector” hook that emits startup inventory events enriched with container-scoped resource limits (cgroup CPU/memory) and filesystem capacity, rather than host-level resources.

Changes:

  • Add a collector CLI subcommand (lifecycle postStart collector) and wire it into member container postStart lifecycle when a hidden collector feature flag is enabled.
  • Introduce a small collector framework (pkg/collect) plus Linux-only system collectors (cgroup limits, filesystem stats) and supporting tests.
  • Add a generic concurrent aggregation utility (pkg/util/collector.go) used to fan-in metrics from multiple collectors.

Reviewed changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
README.md Documents the new collector logger in --log.level help output.
pkg/util/shutdown/shutdown.go Adds process-stable BootID/BootTime helpers used to tag collector events.
pkg/util/k8sutil/lifecycle.go Adds helper to build the postStart exec handler for running the collector.
pkg/util/collector.go New generic concurrent aggregation utility used by collectors.
pkg/util/collector_test.go Unit tests for the new generic util collector.
pkg/deployment/resources/pod_creator_gateway_container.go Enables collector postStart hook for gateway container when feature flag is enabled.
pkg/deployment/resources/pod_creator_arangod.go Enables collector postStart hook for arangod container when feature flag is enabled.
pkg/deployment/features/collector.go Adds hidden collector feature flag definition.
pkg/collect/logger.go Adds a dedicated collector logger.
pkg/collect/collector.go Implements a registry that runs all metric collectors and aggregates their output.
pkg/collect/collector_resource_other.go Non-Linux build stub for host resource collector.
pkg/collect/collector_resource_linux.go Linux host resource collector (CPU count + /proc/meminfo total).
pkg/collect/collector_resource_linux_test.go Tests for the Linux host resource collector.
pkg/collect/collector_filesystem_test.go Tests for filesystem collector behavior.
pkg/collect/collector_filesystem_other.go Non-Linux build stub for filesystem collector.
pkg/collect/collector_filesystem_linux.go Linux filesystem collector using unix.Statfs.
pkg/collect/collector_cgroup_test.go Tests for cgroup v1/v2 limit parsing and “unlimited/absent” behavior.
pkg/collect/collector_cgroup_other.go Non-Linux build stub for cgroup collector.
pkg/collect/collector_cgroup_linux.go Linux cgroup collector reporting CPU/memory limits (v1 + v2).
pkg/collect/collect.go Implements the postStart collector loop and event emission to stdout.
pkg/collect/collect_test.go Tests for registry collection and event construction.
docs/cli/arangodb_operator.md Documents the new collector logger in CLI docs.
cmd/lifecycle_post_start.go Adds the hidden lifecycle postStart collector command and flags.
CHANGELOG.md Adds a changelog entry for the Inventory Collector feature.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/util/collector.go
Comment on lines +63 to +64
// NewCollector creates a Collector. A background goroutine drains pushed items until Done is called,
// so Push never blocks and is safe to call concurrently.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is Adam's #2115 framework - not my collectors. need to confirm with Adam

Comment thread pkg/collect/collector.go
Comment on lines +80 to +100
func (c *collector[T]) Collect() ([]T, error) {
c.lock.Lock()
defer c.lock.Unlock()

out := util.NewCollector[T]()

for _, e := range c.collectors {
e := e
if err := out.Run(func(p util.Pusher[T]) error {
return e.CollectEvents(p)
}); err != nil {
return nil, err
}
}

if err := out.Done(); err != nil {
return nil, err
}

return out.Collect(), nil
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is Adam's #2115 framework - not my collectors. need to confirm with Adam

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants